#include <GL/glut.h>
#include <string.h>
#include <stdlib.h>
#include "HUD.h"
#include "Configuration.h"

bool HUD::GameOver;

HUD::HUD(int *healthP1,int* scoreP1)
{
	PlayerOneHealth = healthP1;
	PlayerOneScore = scoreP1;
};

void HUD::PrintString(float x,float y,void *font,char *txt,float fontSize)
{ 
	glPushMatrix();
	for(int i = 0 ; i < strlen(txt) ; i++)
	{
	  glRasterPos2f(x,y);
	  glutBitmapCharacter(font,txt[i]);
	  x+=fontSize;
	}
	glPopMatrix();
}

void HUD::Display()
{
	glPushMatrix();
	glLoadIdentity();
	char buffer[50];

	glColor4f(0.4,1,0.4,0.6);
	glDisable(GL_LIGHTING);
	glDisable(GL_DEPTH_TEST);


	//orthoStart();
	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity();
	gluOrtho2D(0,Config::ScreenWidth,Config::ScreenHeight,0);
	glScalef(1,-1,1);
	glTranslatef(0,-Config::ScreenHeight,0);
	glMatrixMode(GL_MODELVIEW);

	
	glPushMatrix();
	PrintString(25,Config::ScreenHeight-25,GLUT_BITMAP_HELVETICA_18,"P1 SCORE:",18);
	PrintString(190,Config::ScreenHeight-25,GLUT_BITMAP_HELVETICA_18,itoa(*PlayerOneScore,buffer,10),18);
	PrintString(315,Config::ScreenHeight-25,GLUT_BITMAP_HELVETICA_18,"HEALTH:",18);
	PrintString(440,Config::ScreenHeight-25,GLUT_BITMAP_HELVETICA_18,itoa(*PlayerOneHealth,buffer,10),18);
	glPopMatrix();

	if(GameOver)
	{
		glPushMatrix();
		PrintString(Config::ScreenWidth/2-(72),Config::ScreenHeight/2,GLUT_BITMAP_HELVETICA_18,"GAME OVER",18);
		PrintString(Config::ScreenWidth/2-(96),Config::ScreenHeight/2-20,GLUT_BITMAP_HELVETICA_12,"(Press ESC to exit)",12);
		glPopMatrix();
	}

	//orthoEnd();
	glMatrixMode(GL_PROJECTION);
	glPopMatrix();
	glMatrixMode(GL_MODELVIEW);

};